package com.zhangsheng.handler;

import com.zhangsheng.api.CommonResult;
import com.zhangsheng.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
 
    /**
     * 业务异常，统一处理
     * @param e 异常对象
     * @return ResponseResult 全局异常响应
     */
    @ExceptionHandler(BusinessException.class)
    public CommonResult<String> businessException(BusinessException e) {
        log.info("code={}, message={}", e.getCode(), e.getMessage());
        return CommonResult.failed(e.getMessage());
    }

}